<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
  <script>
    // 'use strict';
    /**function dn(){
      var x =1;
      x =x+1;
    }
    function dn2(){
        var x ="A";
        x =x+1;
    }
    x = x+2;//Uncaught ReferenceError: x is not defined

    //内部函数可以访问外部函数的成员，反之则不行
     function dn(){
        var x =1;
        function dn2(){
            var y = x+1;
        }
        var z = y+1;//Uncaught ReferenceError: y is not defined

    }
    function dn(){
        var x =1;
        function dn2(){
            var x = 'A';
            console.log('inner x=>'+x);
        }
        console.log('outer x =>'+x);
        dn2();
    }
    dn();
    function dn(){
        var x = "x"+y;
        console.log(x);
        var y = 'Y';
    }
    dn();//结果：xundefined
    //所有的变量应该都在函数的前面定义
    function dn2(){
        var x = 1,
            y = x+1,
            z,i,a;


    }
    //全局变量
    var x =1;
    function f(){
        console.log(x);
    }
    f();
    console.log(x);

    var x ="xxx";
    //alert(x);//= window.alert(x);
    //alert(window.x);//所有的全局变量都会自动默认绑定在window对象下
    var old_alert = window.alert;
    old_alert(x);
    window.alert = function (){}
    //发现alert失效了
    window.alert(123);
    //恢复
    window.alert = old_alert;
    window.alert(456);
    //定有唯一全局变量
    var davidapp = {}
    davidapp.name = 'David Niu';
    davidapp.add = function (a,b){
        return a+b;
    }

    function aaa(){
        for (let i = 0; i <100 ; i++) {
            console.log(i);
        }
        console.log(i+1);//i出了作用域还可以使用
    }
     */
    const PI = '3.14';//只读变量
    console.log(PI);
    PI='123';//Uncaught TypeError: Assignment to constant variable.
    console.log(PI);
  </script>

</head>
<body>

</body>
</html>